<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['blog']) && ($_SESSION['blog'] <= 0))) {
	Vfriend_Function::redirect(HOST_BACKEND);
}
$arrParams = $objRequest->getParams();
$intAction = isset($arrParams['paction']) ? $arrParams['paction'] : 0;
$intDetail = isset($arrParams['de']) ? $arrParams['de'] : 0;
$intBlogId = isset($arrParams['blogid']) ? $arrParams['blogid'] : null;
$arrBlogId = isset($arrParams['pblogid']) ? $arrParams['pblogid'] : null;
$strBackUrl= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : HOST_BACKEND;
$intError  = 0;
if($intAction && (isset($arrBlogId) || $intBlogId)) {
	$objBlog	= new Blog();
	switch ($intAction) {
		case 1: // active
		case 5: // suggest	
		case 7: // cancel report		
			if(isset($_SESSION['blog']) && ($_SESSION['blog']&1<<5) != 0) {	
				if($intAction == 1 || $intAction == 7) $intStatus = 2;
				elseif($intAction == 5) $intStatus = 1;	
				if($intDetail == 0) {
					foreach($arrBlogId as $row) {
						$intUserId = $objRequest->getParam('puserid' . $row, 0);
						$intError  = $objBlog->updateStatus($AppUI->id,$row,$intStatus,32,$intUserId);
					}
				} else {
					$intUserId = $objRequest->getParam('uid', 0);
					$intError  = $objBlog->updateStatus($AppUI->id,$intBlogId,$intStatus,32,$intUserId);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 2: // delete
			if(isset($_SESSION['blog']) && ($_SESSION['blog']&1<<3) != 0) {	
				if($intDetail == 0) {
					foreach($arrBlogId as $row) {
						$intUserId = $objRequest->getParam('puserid' . $row, 0);
						$objBlog->updateStatus($AppUI->id,$row,3,8,$intUserId);
					}
				}else {
					$intUserId = $objRequest->getParam('uid', 0);
					$intError  = $objBlog->updateStatus($AppUI->id,$intBlogId,3,8,$intUserId);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 4: // delete database
			if(isset($_SESSION['blog']) && ($_SESSION['blog']&1<<3) != 0 && $AppUI->type > 1) {
				if($intDetail == 0) {
					foreach($arrBlogId as $row) {
						$intUserId = $objRequest->getParam('puserid' . $row, 0);
						$objBlog->delete($AppUI->id,$row,$intUserId);
					}
				} else {
					$intUserId = $objRequest->getParam('uid', 0);
					$objBlog->delete($AppUI->id,$intBlogId,$intUserId);
				}
			}
			else {
				$intError = 1;
			}
			break;	
		case 6: // cancel suggest
			if(isset($_SESSION['blog']) && ($_SESSION['blog']&1<<4) != 0) {				
				if($intDetail == 0) {
					foreach($arrBlogId as $row) {
						$intUserId = $objRequest->getParam('puserid' . $row, 0);
						$objBlog->updateStatus($AppUI->id,$row,2,16,$intUserId);
					}
				} else {
					$intUserId = $objRequest->getParam('uid', 0);
					$objBlog->updateStatus($AppUI->id,$intBlogId,2,16,$intUserId);
				}
			}
			else {
				$intError = 1;
			}
			break;
	}
} else {
	$intError = 1;
}
if($intError == 0) {
	Vfriend_Function::setMsg($arrMessage[$intAction]);
} else {
	Vfriend_Function::setError($arrError[$intError]);	
}
if($intDetail == 0) {
	Vfriend_Function::redirect($strBackUrl);
} else {
	$strRefer	= $objRequest->getParam('refer','');	
	Vfriend_Function::redirect(HOST_BACKEND . 'blog/detail?blogid=' . $intBlogId . '&refer=' . $strRefer);
}
?>